package monitor

import (
	. "gddgame.cc/galaxy/common/dsl/web"
	"gddgame.cc/galaxy/utils/def"
)

func GetMonitorAll(context def.Context, server string) ([]ServerMonitor, error) {
	var monitorList []ServerMonitor
	query := ServerMonitorModel.Query()
	if server != "" {
		query.WhereSql("`server` like ?", "%"+server+"%")
	}
	query.Where("=", "status", 1)
	if _, err := query.Find(&monitorList); err != nil {
		return nil, SystemException(err)
	}
	return monitorList, nil
}

func EditMonitor(context def.Context, id int, data map[string]interface{}) error {
	var monitor ServerMonitor
	var err error
	var ok bool
	if ok, err = ServerMonitorModel.PK(id).One(&monitor); !ok {
		return EmptyExceptionDetail("id不存在", err)
	}
	_, err = ServerMonitorModel.PK(id).Update(data)
	if err != nil {
		return SystemExceptionDetail("更新失败", err)
	}
	return nil
}
